package com.hqyj.javaSpringBoot.modules.account.controller;

import com.hqyj.javaSpringBoot.aspect.MyAnnotation;
import com.hqyj.javaSpringBoot.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AccountController {


	@Autowired
	private UserService userService;

	/**
	 * 127.0.0.1/login
	 * 登录
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/login")
	public String loginPage(ModelMap modelMap) {
		modelMap.put("template", "account/login");
		return "indexSimple";
	}
	
	/**
	 * 127.0.0.1/register
	 * 注册
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/register")
	public String registerPage(ModelMap modelMap) {
		modelMap.put("template", "account/register");
		return "indexSimple";
	}

	@GetMapping("/logout")
	public String logout(){
		userService.logout();
		return "redirct:/login";
	}
	
	/**
	 * 127.0.0.1/account/users
	 * 用户
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/account/users")
	@MyAnnotation
	@RequiresRoles(value={"admin", "manger"}, logical= Logical.OR)
	public String usersPage() {
//		modelmap.put("template", "account/users");
		return "index";
	}


	/**
	 * 127.0.0.1/account/roles
	 * 角色
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/account/roles")
	@MyAnnotation
	@RequiresRoles(value={"admin", "manger"}, logical= Logical.OR)
	public String rolesPage() {
//		modelmap.put("template", "account/users");
		return "index";
	}


	/**
	 * 127.0.0.1/account/roles
	 * 权限
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/account/resources")
	@MyAnnotation
	@RequiresRoles(value={"admin", "manger"}, logical= Logical.OR)
	public String resourcesPage() {
//		modelmap.put("template", "account/users");
		return "index";
	}


	/**
	 * 127.0.0.1/account/user1
	 * 用户
	 * ModelMap给template赋值交付给了拦截器
	 * @return
	 */
	@GetMapping(value="/account/user1")
	@MyAnnotation
	public String user1Page() {
//		modelmap.put("template", "account/users");
		return "index";
	}


	/**
	 * 127.0.0.1/account/profile ---- get
	 */
	@GetMapping("/account/profile")
	public String profilePage() {
		return "index";
	}

}
